package service

import (
	"github.com/syyongx/php2go"
	"hello/models"
	"hello/wl"
)

//登陆完成重新生成Access_token
func ReloadAccessToken()  {

}
type SMessage struct {
	Status bool
	Message interface{}
}

func NewSMessage(status bool,message interface{}) SMessage {
	tempMessage:=SMessage{Status:status,Message:message}
	return tempMessage
}

func UserLogin(email interface{},password interface{}) SMessage  {
	user:=models.User{Email:email.(string)}

	user.FindByEmail()

	if php2go.Empty(user.Id) {
		return NewSMessage(false,"账号不存在")
	}else {
		if wl.WlSha256(password.(string)+user.Salt)==user.Password {
			Access_token:=user.Access_token

			go func() {
				user.ReloadAccessToken()
			}()

			wl.RedisSet(Access_token,user,30)

			return NewSMessage(true,Access_token)


		}else{
			return NewSMessage(false,"密码错误")

		}

	}

}
